package ru.evga.gwt.lib.common.client.ui.dialog;

import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.Widget;

public abstract class AbstractDialog implements IDialog
{
    
    private DialogBox m_dialog;
    private String m_strContentWidth = null;
    private String m_strContentHeight = null;
    
    public AbstractDialog(boolean isModal)
    {
        m_dialog = new DialogBox();
        m_dialog.setModal(isModal);
    }
    
    public void setTitle(String strTitle)
    {
        m_dialog.setText(strTitle);
        
    }
    
    public void open()
    {
        
        DialogSkilet skilet = new DialogSkilet();
        
        skilet.setContent(createContent().asWidget());
        skilet.setButtonBar(createButtonBar());
        
        m_dialog.setWidget(skilet);
        if(getContentWidth() != null)
        {
            skilet.setWidth(getContentWidth());    
        }
        if(getContentHeight() != null)
        {
            skilet.setHeight(getContentHeight());    
        }
        
        
        m_dialog.center();
        m_dialog.show();
    }
    
    
    
    public void close()
    {
        m_dialog.hide();
    }
    
    /**
     * Creates button bar
     */
    abstract Widget createButtonBar();

    /**
     * Creates content
     */
    abstract IsWidget createContent();

    public String getContentWidth()
    {
        return m_strContentWidth;
    }
    
    public String getContentHeight()
    {
        return m_strContentHeight;
    }

    public void setContentWidth(String width)
    {
        m_strContentWidth = width;
    }
    
    public void setContentHeight(String height)
    {
        m_strContentHeight = height;
    }
    
    
    
}
